//
//  YHUserAccount.swift
//  WeiBoYH
//
//  Created by yanhui on 2017/1/8.
//  Copyright © 2017年 yanhui. All rights reserved.
//

import UIKit

class YHUserAccount: NSObject ,NSCoding{
    
    var access_token: String?
    
    var expires_in: Double = 0 {
        didSet {
            
            expires_date = Date(timeIntervalSinceNow: expires_in)
            print(expires_date)
        }
    }
    var expires_date: Date?
   
    var uid: String?
    ///用户昵称
    var screen_name: String?
    ///用户头像地址
    var avatar_large: String?
    
    //KVC
    init(dict: [String : Any]) {
        super.init()
        setValuesForKeys(dict)
    }
    
    //过滤
    override func setValue(_ value: Any?, forUndefinedKey key: String) {    }
    
    
    //实现协议方法
    
    //归档
    func encode(with aCoder: NSCoder) {
        aCoder.encode(access_token, forKey: "access_token")
        aCoder.encode(expires_date, forKey: "expires_date")
        aCoder.encode(uid, forKey: "uid")
        aCoder.encode(screen_name, forKey: "screen_name")
        aCoder.encode(avatar_large, forKey: "avatar_large")
        
    }
    
    //解档
    required init?(coder aDecoder: NSCoder) {
        //给属性赋值
        self.access_token = aDecoder.decodeObject(forKey: "access_token") as? String
        self.expires_date = aDecoder.decodeObject(forKey: "expires_date") as? Date
        self.uid = aDecoder.decodeObject(forKey: "uid") as? String
        self.screen_name = aDecoder.decodeObject(forKey: "screen_name") as? String
        self.avatar_large = aDecoder.decodeObject(forKey: "avatar_large") as? String
    }
    
}



